<?php

function get_where($param){

    $where = array();
    $where_str = "";
    if(isset($param['role_id']) && $param['role_id']){
        $where[] = "$5=={$param['role_id']}";
    }

    if(!empty($where)){
        $where_str = " && ".implode(" && ",$where);
    }
    return $where_str;
}

/**
 *
 * @param $param
 */
//http://log.bajian.wan.sogou.com/index.php?a=get_server_ingot_daily_total_log&server_id=10001
function get_server_ingot_daily_total_log($param){

    $param['log_path'] = str_replace("*",date("d",$param['log_time']),$param['log_path']);
    //日期 总产出 充值产出(正常正常 平台币充值) 游戏产出 内部产出 赠送产出  服务器消耗  服务器剩余
    //游戏产出
    //内部产出 go_inner_rebate.now_apply_ingot
    //赠送产出 go_rebate.ingot

    //游戏产出

    if($param['coin_type']==2){

        $cmd_binding_ingot = <<<EOT
awk 'BEGIN {FS=",";ybsum=0};{ybsum=ybsum+$8};END {print ybsum}' {$param['log_path']}/binding_ingot_[0-9]*
EOT;
        $cmd_binding_ingot_expend = <<<EOT
awk 'BEGIN {FS=",";ybsum=0};{ybsum=ybsum+$11};END {print ybsum}' {$param['log_path']}/binding_ingot_expend_[0-9]*
EOT;
        $cmd_binding_ingot_expend_other = <<<EOT
awk 'BEGIN {FS=",";ybsum=0};{ybsum=ybsum+$8};END {print ybsum}' {$param['log_path']}/binding_ingot_expend_other_[0-9]*
EOT;
		$data_binding_ingot = exec_cmd($cmd_binding_ingot,$param);
        $data_binding_ingot_expend = exec_cmd($cmd_binding_ingot_expend,$param);
        $data_binding_ingot_expend_other = exec_cmd($cmd_binding_ingot_expend_other,$param);
//        echo "<pre>";
//        print_r($data_binding_ingot);
//        print_r($data_binding_ingot_expend);
//        print_r($data_binding_ingot_expend_other);
        $log = array(
            'ingot_total'=>$data_binding_ingot['data'][0],
            'server_ingot_cost'=>abs($data_binding_ingot_expend['data'][0])+abs($data_binding_ingot_expend_other['data'][0])
        );
        $data['total'] = 1;
        $data['per_page'] = 1;
        $data['total_page'] = 1;
        $data['page'] = 1;


    }else{
        //游戏产出
        $cmd_ingot_other = <<<EOT
awk 'BEGIN {FS=",";ybsum=0};{ ybsum=ybsum+$8}; END {print ybsum}' {$param['log_path']}/ingot_other_[0-9]*
EOT;
        //元宝购买行为记录（ingot_expend）
        $cmd_ingot_expend = <<<EOT
awk 'BEGIN {FS=",";ybsum=0};{ ybsum=ybsum+$11}; END {print ybsum}' {$param['log_path']}/ingot_expend_[0-9]*
EOT;
        //元宝其他消耗记录（ingot_expend_other）
        $cmd_ingot_expend_other = <<<EOT
awk 'BEGIN {FS=",";ybsum=0};{ ybsum=ybsum+$8}; END {print ybsum}' {$param['log_path']}/ingot_expend_other_[0-9]*
EOT;

        $data_ingot_other = exec_cmd($cmd_ingot_other,$param);//
        $data_ingot_expend = exec_cmd($cmd_ingot_expend,$param);
        $data_ingot_expend_other = exec_cmd($cmd_ingot_expend_other,$param);
        /*
        echo "<pre>";
        print_r($data_ingot_other);
        print_r($data_ingot_expend);
        print_r($data_ingot_expend_other);*/

        $log = array(
            'game_ingot_total'=>$data_ingot_other['data'][0],
            'server_ingot_cost'=>abs($data_ingot_expend['data'][0])+abs($data_ingot_expend_other['data'][0])

        );
        $data['total'] = 1;
        $data['per_page'] = 1;
        $data['total_page'] = 1;
        $data['page'] = 1;
    }


    ajax_return($data['total'],$data['per_page'],$data['total_page'],$data['page'],$log);
}